package com.cds.drizzt.exception;

import com.cds.drizzt.utils.enums.HttpCodeEnum;
import lombok.Getter;

/**
 * 业务异常基类，主动抛出的可控异常
 */
@Getter
public class BusinessException extends RuntimeException {
    private final HttpCodeEnum httpCodeEnum;  // 关联业务异常状态码枚举
    private final String requestId;  // 请求ID，用于跟踪和日志记录

    /**
     * 构造函数，用于创建业务异常对象,直接传入错误码枚举
     * @param httpCodeEnum 关联的业务异常状态码枚举
     */
    public BusinessException(HttpCodeEnum httpCodeEnum) {
        super(httpCodeEnum.getMsg());
        this.httpCodeEnum = httpCodeEnum;
        this.requestId = null;
    }
    /**
     * 构造函数，用于创建业务异常对象，自定义消息覆盖枚举默认消息
     * @param httpCodeEnum 关联的业务异常状态码枚举
     * @param customMsg 自定义异常消息
     */
    public BusinessException(HttpCodeEnum httpCodeEnum, String customMsg) {
        super(customMsg);
        this.httpCodeEnum = httpCodeEnum;
        this.requestId = null;
    }
    /**
     * 构造函数，用于创建业务异常对象，自定义消息覆盖枚举默认消息，同时传入请求ID
     * @param httpCodeEnum 关联的业务异常状态码枚举
     * @param customMsg 自定义异常消息
     * @param requestId 请求ID，用于跟踪和日志记录
     */
    public BusinessException(HttpCodeEnum httpCodeEnum, String customMsg, String requestId) {
        super(customMsg);
        this.httpCodeEnum = httpCodeEnum;
        this.requestId = requestId;
    }
}
